<template>
  <div class="articles">
    <h3>来自生活</h3>
    <transition-group
      name="list"
      v-bind:css="false"
      v-on:before-enter="beforeEnter"
      v-on:enter="enter"
    >
      <div
        class="body_articles"
        v-for="(item, index) in $store.state.articlesList"
        :key="item"
        @mouseenter="isopen = index"
        @mouseleave="isopen = -1"
      >
        <div class="articles_click">
          <transition name="click-top">
            <div class="click_top" v-show="isopen === index">
              <router-link :to="{ path: '/showartcle', query: { id: item.id } }">
                <span>查看</span>
              </router-link>
            </div>
          </transition>
          <transition name="click-bottom">
            <div class="click_bottom" v-show="isopen === index">
              <span></span>
            </div>
          </transition>
        </div>
        <img
        :src="require('../../assets/' + item.imgUrl)"
        alt="2022 7 28 2"
        class="bg"
      />
        <div class="date">
          <span>{{ item.new_date ? item.new_date[0] : 2022 }}</span>
          <div class="date_bottom">
            <h5>{{ item.new_date ? item.new_date[1] : "01" }}</h5>
            <p>{{ item.new_date ? item.new_date[2] : "01" }}</p>
          </div>
        </div>
        <div class="article_main">
          <div class="title">
            <h2>{{ item.title }}</h2>
          </div>
          <div class="body">
            <p>
              {{ item.body }}
            </p>
          </div>
        </div>

        <div class="mask"></div>
      </div>
    </transition-group>

    <pages></pages>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
import pages from "@/components/Views/Pages.vue";
export default {
  mounted() {
    this.get_Articles({ page: this.page, pagesize: this.pagesize });
  },
  computed: {
    ...mapState(["pages", "page", "pagesize"]),
  },
  data() {
    return {
      isopen: -1,
      style:
        "background-image:url(https://img.gejiba.com/images/350b3049504e2b1dbf08c160cc4c0701.jpg);",
      signin_active: false,
    };
  },
  methods: {
    ...mapActions(["get_Articles"]),
    beforeEnter(el) {
      el.style.opacity = 0;
    },
    enter(el, done) {
      // console.log(el.dataset.index)
      let delay = el.dataset.index * 300;
      setTimeout(() => {
        el.style.transition = "opacity 0.3s ";
        el.style.opacity = 1;
        el.style.animation = "one-in 0.3s infinite";
        el.style["animation-iteration-count"] = 1;
        done();
      }, delay);
    },
  },
  components: {
    pages,
  },
};
</script>

<style lang="less">
@keyframes move1 {
  0% {
    transform: scale(0.8);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes out1 {
  0% {
    transform: translateX(0px);
    opacity: 1;
  }
  100% {
    transform: translateX(50px);
    opacity: 0;
  }
}
@keyframes move2 {
  0% {
    transform: scale(0.8);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes out2 {
  0% {
    transform: translateX(0px);
    opacity: 1;
  }
  100% {
    transform: translateX(-50px);
    opacity: 0;
  }
}
@font-face {
  font-family: "english";
  src: url("/src/fonts/Babyque.ttf");
}
@font-face {
  font-family: "xda01";
  src: url("/src/fonts/上首刺云体.ttf");
}
@font-face {
  font-family: "xda02";
  src: url("/src/fonts/极字经典综艺简繁.ttf");
}
@keyframes one-in {
  from {
    height: 470px;
    transform: rotateY(75deg);
  }
  to {
    height: 470px;
    transform: rotateY(0deg);
    /* transform-origin: 145%, 0; */
  }
}
.articles {
  user-select: none;
  position: relative;
  flex: 1;
  background-color: rgba(237, 237, 237, 0.595);
  box-shadow: 0 0 5px 2px rgb(47, 47, 47);
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 5px;
  .list-enter-active,
  .list-leave-active {
    transition: opacity 0.4s;
  }
  .list-enter-active {
    animation: one-in 0.4s infinite;
  }
  .list-enter,
  .list-leave-to {
    opacity: 0;
  }
  h3 {
    color: rgb(68, 68, 68);
    text-shadow: 0 0 3px rgb(110, 110, 110);
    border-radius: 5px;
    padding: 5px;
    border: 3px solid rgb(87, 87, 87);
    border-top: 0;
    font-size: 30px;
    box-shadow: 0 0 2px 3px rgb(104, 104, 104);
    margin-bottom: 25px;
  }
  .body_articles {
    display: block;
    position: relative;
    width: 686px;
    height: 470px;
    padding: 18px;
    box-shadow: 0 0 5px 2px rgb(47, 47, 47);
    border-radius: 10px;
    padding-top: 30px;
    margin-bottom: 60px;

    .articles_click {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      position: absolute;
      .click-top-enter-active {
        animation: move1 0.2s ease-out;
      }

      .click-top-leave-active {
        animation: out1 0.3s ease-out;
      }
      .click-bottom-enter-active {
        animation: move2 0.2s ease-in;
      }
      .click-bottom-leave-active {
        animation: out2 0.3s ease-in;
      }

      .click_top {
        position: relative;
        flex: 2;
        background-color: rgba(116, 144, 150, 0.513);
        z-index: 99;
        span {
          box-shadow: 0 0 4px 6px rgb(190, 163, 163);
          text-align: center;
          line-height: 40px;
          background-color: rgb(133, 133, 133);
          color: aliceblue;
          font-weight: 600;
          font-size: 22px;
          border-radius: 10px;
          display: block;
          width: 100px;
          height: 40px;
          position: absolute;
          bottom: -15px;
          left: 50%;
          transform: translateX(-50%);
          z-index: 100;
        }
        span:hover {
          cursor: pointer;
        }
      }
      .click_bottom {
        position: relative;
        flex: 3;
        background-color: rgba(116, 144, 150, 0.513);
        span {
          border-radius: 10px;
          text-align: center;
          line-height: 40px;
          background-color: rgba(115, 115, 115, 0.208);
          display: block;
          width: 100px;
          height: 15px;
          position: absolute;
          top: 0;
          left: 50%;
          transform: translateX(-50%);
        }
      }
    }
    .bg {
      position: absolute;
      width: 660px;
      height: 430px;
      // background-image: url(https://img.gejiba.com/images/350b3049504e2b1dbf08c160cc4c0701.jpg);
      background-size: 100%;
      background-repeat: "no-repeat";
      z-index: -1;
    }
    .article_main {
      width: 660px;
      padding: 0;
      .title {
        margin-top: 100px;
        display: flex;
        justify-content: center;
        h2 {
          padding: 0 10px;
          height: 50px;
          color: rgb(54, 54, 54);
          font-family: xda01;
          font-size: 40px;
        }
      }
      .body {
        width: 100%;
        background-color: rgba(240, 248, 255, 0.551);
        height: 60px;
        display: flex;
        p {
          font-size: 22px;
          display: block;
          width: 100%;
          height: 100%;
          color: rgb(2, 2, 2);
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2; /*这里设置几行*/
          overflow: hidden;
        }
      }
    }

    .date {
      position: absolute;
      top: -35px;
      right: -10px;
      width: 90px;
      height: 58px;
      background-color: rgba(98, 98, 98, 0.909);
      box-shadow: 0 0 5px 5px rgba(211, 211, 211, 0.529);
      border-radius: 18px;
      display: flex;
      flex-direction: column;
      align-items: center;
      z-index: 99;
      span {
        font-size: 16px;
        color: rgb(255, 255, 255);
        font-weight: 900;
      }
      .date_bottom {
        display: flex;
        justify-content: center;
        align-items: center;
        h5 {
          font-size: 18px;
          margin-right: 4px;
        }
        p {
          font-size: 30px;
          font-weight: 600;
          color: rgb(5, 200, 234);
        }
      }
    }

    .mask {
      top: 0;
      left: 0;
      position: absolute;
      width: 100%;
      height: 100%;
      background-color: rgba(115, 115, 115, 0.208);
      z-index: 1;
    }
  }
}
</style>